package menu;
import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;

import chesskers.Driver;
import chesskers.ImagePanel;
import chesskers.UIManager;

public class TimeGameFrame extends MenuWindow{
	
	ImagePanel panel_mainmenu = new ImagePanel(new ImageIcon("img/background.png").getImage());
	JButton button_5timedGame = new JButton("5 Minute Game");
	JButton button_7timedGame = new JButton("7 Minute Game");
	JButton button_unlimitedGame = new JButton("Unlimited Time Game");
	JButton button_mm_quit = new JButton("Back");
	
	public TimeGameFrame() {
		super("Chess-kers!");
		
		button_5timedGame.setBounds(150, 100, 300, 50);
		button_7timedGame.setBounds(150, 160, 300, 50);
		button_unlimitedGame.setBounds(150, 220, 300, 50);
		button_mm_quit.setBounds(150, 415, 300, 30);
		
		panel_mainmenu.add(button_5timedGame);
		MakeButtonAction(button_5timedGame, "5min");		
		panel_mainmenu.add(button_7timedGame);
		MakeButtonAction(button_7timedGame, "7min");
		panel_mainmenu.add(button_unlimitedGame);
		MakeButtonAction(button_unlimitedGame, "unlim");
		panel_mainmenu.add(button_mm_quit);
		MakeButtonAction(button_mm_quit, "back");
		
		this.add(panel_mainmenu);
		
		setSize(600, 500);
		setBackground(Color.red);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setResizable(false);
        setVisible(true);
	}

	@Override
	public void Action(String cmd) {
		// TODO Auto-generated method stub
		switch (cmd) {
		
		case "5min":
			Driver.timeLimit = 5 * 60;
			System.out.println(Driver.timeLimit);
			select();
			break;	
		case "7min":
			Driver.timeLimit = 7 * 60;
			select();
			break;			
		case "unlim":
			Driver.timeLimit = 0 * 60;
			select();
			break;			
		case "back":
			if (Driver.state == Driver.state.TimeCheck){
				Driver.state = Driver.state.CheckSelect2;
			}
			else if (Driver. state == Driver.state.TimeChess){
				Driver.state = Driver.state.ChessSelect2;
			}
			new UIManager().start();
		    dispose();
			break;		
		default:
			throw new UnsupportedOperationException("Invalid button code: "+cmd);
		}
	}
	
	private void select() {
		if (Driver. state == Driver.state.TimeCheck){
			Driver.state = Driver.state.CheckGame;
		}	
		else if (Driver. state == Driver.state.TimeChess){
			Driver.state = Driver.state.ChessGame;
		}
		new UIManager().start();
	    dispose();
	}
}